<?php
//抑制所有错误信息
@error_reporting(E_ALL &~ E_NOTICE);
@set_time_limit(0);
date_default_timezone_set('PRC');
if (!isset($_SERVER['PHP_SELF']) || empty($_SERVER['PHP_SELF'])) $_SERVER['PHP_SELF']=$_SERVER['SCRIPT_NAME'];
header('Content-type:text/html; charset=utf-8'); //强制语言
/*****************************************/
/*		 定义常用常量、引入必要文件		*/
/*****************************************/
define('ROOT',str_replace('\\','/',dirname(__FILE__)).'/');
define('INC',ROOT.'include/');
define('DATA',ROOT.'data/');
define('TPL',DATA.'template/');
define('EXEC',DATA.'exec/');
require(DATA.'db.inc.php');
require(DATA.'config.inc.php');
require(INC.'common.func.php');
require(INC.'pdo_mysql.class.php');
require(INC.'ssdb.class.php');
require(INC.'base.php');
/*****************************************/
/*				 初始变量				 */
/*****************************************/
$time=time();
$_ENV=array();
unset($HTTP_GET_VARS,$HTTP_POST_VARS,$HTTP_COOKIE_VARS,$HTTP_SERVER_VARS,$HTTP_ENV_VARS);
$m=getgpc('m');
$a=getgpc('a');
$isLogin=FALSE;
$uid=0;
$auth=getgpc('auth','R');;
if (in_array($m,array('index','member','node'),TRUE)) {
	if(is_file('model/'.$m.'.php')) {
		require('model/'.$m.'.php');
	} else {
		exit(json_encode(array('success'=>0,'errcode'=>104,'errmsg'=>'API Not Found')));
	}
	$_ENV['_model']=$m::getInstance();
	$method='on'.$a;
	if(method_exists($_ENV['_model'],$method) && $a{0}!='_') {
		if (!empty($auth)) {
			$dbauth=$_ENV['_model']->sql->GetOne('select','auth',array('row'=>'*','where'=>array(array('name'=>'auth','type'=>'eq','val'=>$auth))));
			if (!empty($dbauth['overdue'])) {
				if (intval(str_replace('-','',$dbauth['overdue']))<intval(date('Ymd'))) { //Auth已过期
					$_ENV['_model']->sql->query('removeauth','delete','auth',array('where'=>array(array('name'=>'auth','type'=>'eq','val'=>$auth))));
				} else {
					$isLogin=TRUE;
					$uid=$dbauth['uid'];
				}
			}
		}
		$result=$_ENV['_model']->$method();
		echo json_encode($result);
	} else {
		exit(json_encode(array('success'=>0,'errcode'=>104,'errmsg'=>'API Not Found')));
	}
} else {
	exit(json_encode(array('success'=>0,'errcode'=>104,'errmsg'=>'API Not Found')));
}
?>